<?php 

function option($items, $parent_id, $cat_id, $level=0) {
    foreach ($items as $item) {
        if ($item['id']==$cat_id) continue;
        
        $selected = ($item['id']==$parent_id) ? 'selected' : '';
        echo '<option value="'.$item['id'].'" '.$selected.'>';
        echo str_repeat('├─', $level).$item['name'];
        if (isset($item['children']) && is_array($item['children'])) {
            option($item['children'], $parent_id, $cat_id, $level+1);
        }
        echo '</option>';
    }
}
?>
<style>
.max-line1 {
    text-overflow: -o-ellipsis-lastline;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;	
}
.max-line2 {
    text-overflow: -o-ellipsis-lastline;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
</style>
<style>
.media-body .summary {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
	text-overflow: ellipsis;
    overflow: hidden;
}
.media-list img {width: 200px;}
@media (max-width: 425px)  {
    .media-list img {width: 115px;}	
    .media-body .summary {display: none;}
}
</style>

<h3 class="page-header">设备列表 
<a href="<?= URL::site('deviceInfo/add');?>" class="ajax-click">+</a>
</h3>

<form class="form-inline ajax-submit" method="get">

    <div class="form-group">
        <select class="form-control" name="status">
			<option value="">选择状态</option>
			<option value="1" <?php if(Arr::get($_GET, 'status')==1):?>selected<?php endif;?>>有档期</option>
			<option value="2" <?php if(Arr::get($_GET, 'status')==2):?>selected<?php endif;?>>无档期</option>
        </select>
    </div>
    <div class="form-group">
        <select class="form-control" name="is_recommend">
			<option value="">选择推荐状态</option>
			<option value="0" <?php if(Arr::get($_GET, 'is_recommend')=='0'):?>selected<?php endif;?>>不推荐</option>
			<option value="1" <?php if(Arr::get($_GET, 'is_recommend')=='1'):?>selected<?php endif;?>>推荐</option>
        </select>
    </div>
    <div class="form-group">
        <select class="form-control" name="cid">
			<option value="">选择分类</option>
			<?php foreach($deviceCategory as $item): ?>
			<option value="<?php echo $item['id']?>" <?php if(Arr::get($_GET, 'cid')==$item['id']):?>selected<?php endif;?>><?php echo $item['name']?></option>
    		<?php endforeach; ?>	
        </select>
    </div>
    <div class="form-group">
        <div class="input-group">
            <input type="text" class="form-control" name="name" value="<?php echo Arr::get($_GET, 'name')?>" placeholder="">
            <span class="input-group-btn">
                <button class="btn btn-info" type="submit">查找</button>
            </span>
        </div>
     </div>
</form>
<br>

<ul class="media-list">
<?php foreach($list as $item): ?>
    <li class="media">
        <div class="media-left">
            <?php if (strpos($item['pic'], '://') !== false):?>
            <?= HTML::image($item['pic'].'?x-oss-process=image/resize,m_fill,h_220,w_360') ?>
            <?php else:?>
            <?= HTML::image('/imagefly/w160-h120-c/' . $item['pic']) ?>
            <?php endif;?>
        </div>
        <div class="media-body">
            <h4 class="media-heading"><a href="//wx.redcells.cc/article?id=<?= $item['id']?>" target="_blank"><?= $item['name'] ?></a></h4>
            <p class="text-muted summary">区域:<?= $item['area'] ?></p>
            <p class="text-muted summary">价格:<?= $item['price'] ?>元/天</p>
            
            <p class="text-muted summary">描述:<?= $item['desc'] ?></p>
            <div class="text-muted max-line1"><?= date('Y-m-d H:i:s', $item['edit_time']) ?></div>
            
            <?php if ($item['status']==1):?>
            <a href="<?= URL::site('deviceInfo/close?id='.$item['id']);?>" class="btn btn-info btn-xs ajax-update">有档期</a>
            <?php else:?>
            <a href="<?= URL::site('deviceInfo/open?id='.$item['id']);?>" class="btn btn-danger btn-xs ajax-update">无档期</a>
            <?php endif;?>
            
    	    <a href="<?= URL::site('deviceInfo/edit')?>?id=<?= $item['id'] ?>" class="btn btn-info btn-xs ajax-click">修改</a>
        </div>
    </li>
<?php endforeach; ?>
</ul>

<?= $pager ?>
